<template>
  <div>
    <div class="top">
      <div class="search-box">
        <span class="search-txt">
          <slot>订单编号：</slot><!-- 插槽 -->
        </span>
        <div class="search">
          <el-input
            class="searchCode"
            v-model="input"
            placeholder="请输入"
          ></el-input>
        </div>

      </div>
      <div class="date-box">
        <span class="search-txt">
          选择日期：
        </span>
        <el-date-picker
          v-model="value1"
          value-format="yyyy-MM-dd"
          type="daterange"
          align="center"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        >
        </el-date-picker>
        <el-button
          type="primary"
          @click='searchFn'
        ><i class="el-icon-zoom-in"></i>查询</el-button>

      </div>
    </div>
    <!-- 列表区域 -->
    <div class="list">
      <el-table
        :data="classList"
        style="width: 100%"
        size='medium'
      >
        <el-table-column
          type="index"
          label="序号"
          width="70"
        >
          <!--  type="index" :index="indexMethod" element表单中的方法 -->

        </el-table-column>
        <el-table-column
          prop="orderNo"
          label="订单编号"
          show-overflow-tooltip
          width="150"
        >
        </el-table-column>

        <el-table-column
          prop="skuName"
          label="商品名称"
          width="120"
           show-overflow-tooltip
        >
        </el-table-column>

        <el-table-column
          prop="amount"
          label="订单金额(元)"
        >
        </el-table-column>

        <el-table-column
          prop="innerCode"
          label="设备编号"
        >
        </el-table-column>

        <el-table-column
          prop="status"
          label="订单状态"
          :formatter='formatter'
        >
        </el-table-column>

        <el-table-column
          prop="createTime"
          label="订单日期"
        >
        </el-table-column>
        <!-- 操作 -->
        <el-table-column
          fixed="right"
          label="操作"
          width="100"
        >
          <template v-slot='{row}'>
            <el-link
              type="primary"
              @click="detailFn(row)"
            >查看详情</el-link>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <div class="page">
        <el-pagination
          @current-change="handleCurrentChange"
          :current-page="currentPage1"
          layout="slot,next,prev"
          prev-text='上一页'
          next-text='下一页'
          :total="totalCount "
        >
          <template>
            <span class="num-txt">
              共{{totalCount}}条记录
              第{{currentPage1}}/{{totalPage}}页
            </span>
          </template>
          <!--  @current-change 当前页变动时触发的事件 -->
        </el-pagination>
      </div>
    </div>

    <!-- 查看详情对话框 -->
    <el-dialog
      title="订单详情"
      :visible.sync="dialogFormVisible"
    >
      <div
        data-v-1988bcc0=""
        class="order-status"
      >
        <div class="leftbx">
          <img
            data-v-1988bcc0=""
            src=""
            class="icon"
          ><span
            data-v-1988bcc0=""
            class="status"
          >出货成功</span>

        </div>
        <img
          data-v-1988bcc0=""
          src="https://likede2-admin.itheima.net/img/pic_2.3b5af41c.png"
          class="pic"
        >
      </div>
      <el-form
        :model="form"
        class="detail"
      >
        <div class="left">
          <el-form-item
            label="订单编号:"
            :label-width="formLabelWidth"
          >
            <span>{{form.orderNo}}</span>
          </el-form-item>
          <el-form-item
            label="设备编号:"
            :label-width="formLabelWidth"
          >
            <span>{{form.innerCode}}</span>
          </el-form-item>

          <el-form-item
            label="完成时间:"
            :label-width="formLabelWidth"
          >
            <span>{{form.updateTime}}</span>
          </el-form-item>
          <el-form-item
            label="设备地址:"
            :label-width="formLabelWidth"
          >
            <span>{{form.addr}}</span>
          </el-form-item>

        </div>

        <div class="right">
          <el-form-item
            label="商品名称:"
            :label-width="formLabelWidth"
          >
            <span>{{form.skuName}}</span>
          </el-form-item>
          <el-form-item
            label="订单金额:"
            :label-width="formLabelWidth"
          >
            <span>{{form.amount}}</span>
          </el-form-item>

          <el-form-item
            label="创建时间:"
            :label-width="formLabelWidth"
          >
            <span>{{form.createTime}}</span>
          </el-form-item>
          <el-form-item
            label="支付方式:"
            :label-width="formLabelWidth"
          >
            <span>{{form.payType}}</span>
          </el-form-item>

        </div>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>

import Status from '@/constant/status'
import { orderSearch } from '@/api/order'

export default {
  name: 'Order-page',
  async created () {
    // 商品类型
    this.handleCurrentChange()// 当前页变动时触发
  },
  methods: {
    formatter (row, column, cellValue, index) {
      const item = Status.Status.find(item => item.id === cellValue)
      return item ? item.value : '出货失败'
    },
    // 查看详情
    detailFn (row) {
      this.dialogTableVisible = true
      this.dialogFormVisible = true
      console.log(row)
      this.form = { ...row }
    },
    // 分页
    async handleCurrentChange (val = 1) {
      const res1 = await orderSearch({ pageIndex: val, pageSize: this.pageSize, orderNo: this.input, startDate: this.value1[0], endDate: this.value1[1] })
      console.log(res1)
      this.classList = res1.data.currentPageRecords.map(item => {
        return {
          orderNo: item.orderNo,
          skuName: item.skuName,
          amount: (item.amount * 0.01).toFixed(2),
          innerCode: item.innerCode,
          status: item.status,
          createTime: this.$moment(item.createTime).format('YYYY.MM.DD HH:mm:ss'),
          addr: item.addr,
          updateTime: this.$moment(item.updateTime).format('YYYY.MM.DD HH:mm:ss'),
          payType: item.payType === 1 ? '支付宝支付' : '微信支付'
        }
      })
      this.pageIndex = res1.data.pageIndex
      this.totalPage = res1.data.totalPage
      this.currentPage1 = val
      this.totalCount = Number(res1.data.totalCount)// 转化成数字
      // console.log(`当前页: ${val}`);
    },
    // 查询
    async searchFn () {
      // 1.搜索订单号
      if (this.input) {
        this.handleCurrentChange()
        // 2.搜索日期
      } else if (this.value1) {
        this.handleCurrentChange()
      }
    }
  },
  data () {
    return {
      // 搜索
      value1: '',
      input: '',
      /* 查看详情 */
      form: '',
      formLabelWidth: '90px',
      dialogTableVisible: false,
      dialogFormVisible: false,
      /* ----------------- */
      currentPage1: 1, // 当前页
      pageSize: 10,
      pageIndex: 1,
      totalPage: 0,
      totalCount: 0, // 期待是一个数字
      // flag: false,
      classList: [
        { // 商品类型
          orderNo: '',
          skuName: '',
          amount: 0,
          innerCode: '',
          status: 0,
          createTime: ''
        }]
      // dialogVisible: false,
      // text: ''
    }
  }
}

</script>

<style lang='less' scoped>
  .order-status {
    background-color: #f8f8f8;
    display: flex;
    justify-content: space-between;
    padding: 0 50px;
    line-height: 68px;
    font-size: 16px;
  }
  .icon {
    width: 30px;
    height: 30px;
    margin-bottom: -10px;
    margin-right: 20px;
  }
  // .leftbx{
  //   width: 150px;
  // }
  .detail {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
  }
  .el-form .detail {
    margin-left: 5px;
  }
  .text {
    font-size: 14px;
  }

  .item {
    padding: 18px 0;
  }

  .box-card {
    width: 480px;
  }
  ::v-deep .el-input[data-v-76a652b8] {
    width: 201px;
    height: 38px;
  }
  .top {
    height: 80px;
    margin-bottom: 20px;
    background-color: #fff;
    display: flex;
    text-align: center;
  }
  .search-box {
    margin-left: 10px;
    display: flex;
    justify-content: space-between;
    width: 300px;
    height: 80px;
    align-items: center;
  }
  .date-box {
    margin-left: 10px;
    display: flex;
    justify-content: space-between;
    width: 550px;
    height: 80px;
    align-items: center;
  }
  .search-txt {
    font-style: 14px;
  }
  .search {
    width: 210px;
    height: 56px;
    margin-top: 15px;
  }
  .el-icon-zoom-in {
    margin-right: 10px;
    font-size: 19px;
    margin-top: 1px;
  }
  .pageMini {
    .el-pagination {
      margin-top: 15px;
    }
  }
  // ::v-deep .el-table_27_column_117     .is-leaf .el-table__cell{
  //   margin-left: 20px;

  // }
  ::v-deep .el-input__suffix-inner {
    pointer-events: all;
    display: flex;
    flex-direction: column;
  }
  ::v-deep .el-input .el-input__count .el-input__count-inner {
    background: #ffffff;
    line-height: 40px;
    display: inline-block;
    padding: 0 0px;
    height: 0px;
  }
  ::v-deep .el-input__suffix {
    position: absolute;
    height: 100%;
    right: 0px;
    top: 0;
    text-align: center;
    color: #fff;
    transition: all 0.3s;
    pointer-events: none;
    width: 30px;
  }
  ::v-deep .el-select > .el-input {
    display: block;
    width: 398px;
  }
  .num-txt {
    font-size: 16px !important;
    color: #dbdfe5 !important;
    font-weight: 400;
  }
  ::v-deep .el-pagination .btn-prev,
  ::v-deep .el-pagination .btn-next {
    width: 70px;
    height: 32px;
    margin: 0 16px;
    border-radius: 2px;
    background-color: #d5ddf8;
    color: #606266;
    float: right;
  }
  ::v-deep .el-pagination .btn-prev {
    float: right;
  }
  ::v-deep .el-dialog__footer {
    text-align: center;
  }
  .el-form-item__label {
    margin-right: 25px;
    font-size: 15px;
  }
  .el-input {
    width: 400px;
    height: 38px;
  }

  .page {
    width: 1100px;
    // display: flex;
    justify-content: space-between;
    position: absolute;
    bottom: 0;
    left: 0;
    background: #fff;
    padding: 40px 16px;
    margin-left: 20px;
    margin-right: 40px;
  }
  // ::v-deep.el-table__header-wrapper{
  //   background-color: #f3f6fb;
  // }
  .el-button.el-button--warning {
    margin-bottom: 10px;
  }
  .list {
    position: relative;
    height: 650px;
    background-color: #fff;
    padding: 25px;
  }

  /* .el-button.el-button--warning{
                    margin-left: 10px;
                    margin-top: 20px;

                  } */
  .search-box.el-button.el-button--primary,
  .list.el-button.el-button--warning {
    width: 85px;
    height: 30px;
    font-size: 16px;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 36px;
    padding: 0;
    /* background-color: #5f84ff; */
    border: none;
    text-align: center;
  }
  .el-icon-circle-plus-outline {
    margin-right: 10px;
    font-size: 19px;
    margin-top: 1px;
  }
  .el-link.el-link--primary {
    margin-right: 10px;
  }
</style>
